/*
 Lucdt Overlay Libray
 */
var Overlay = function () {};
 Overlay.prototype = {
	 
	overlayCount : 0,
				 
	modal:function(config){
				this.overlayCount ++;	
				var 
				method = {},
				$overlay,
				$modal,
				$content,
				$close;
				
				
				
				// Center the modal in the viewport
				method.center = function () {
					var top, left;

					top = Math.max($(window).height() - $modal.outerHeight(), 0) / 2;
					left = Math.max($(window).width() - $modal.outerWidth(), 0) / 2;

					$modal.css({
						top:top + $(window).scrollTop(), 
						left:left + $(window).scrollLeft()
					});
				};

				// Open the modal
				method.open = function (settings) {
					//$content.empty().append(settings.content);
					var w_title='',w_w='',w_h='',w_url='',w_data='',w_content='';
				
					if(settings){
						w_title = settings.title;
						w_w = settings.width;
						w_h = settings.height;
						w_url = settings.url;
						w_data = settings.data;
						w_content = settings.content;
					}
					
					if(w_content){ 
							//intant content
							$content.append(w_content);
						}else{
							if(w_url){
								//get content ajax	
								$.ajax({
									   type: "POST",
									   url: w_url,
									   data: 'ajax=1&'+w_data,
									   success: function(data){
										   try{		  
												var data = $.parseJSON(data);
												if(data.html) {
													$("#overlay_"+this.overlayCount).html(data.html);
												}
										   }catch(e){
												Common.jsonError();   
										   }
									   }
									});	 
								
							}
						}
						if(w_title){
							$title.html(w_title);
						}
						
						if(w_w){
							$content.width(w_w-40);	
						}
						
						if(w_h){
							$content.height(w_h);	
						}
					
					$modal.css({
						width: w_w || 'auto', 
						height: w_h || 'auto'
					});

					method.center();
					$(window).bind('resize.modal', method.center);
					$modal.show();
					$overlay.show();
				};

				// Close the modal
				method.close = function () {
					$modal.hide();
					$overlay.hide();
					$content.empty();
					$(window).unbind('resize.modal');
				};

				// Generate the HTML and add it to the document
				$title = $('<div class="overlayTitle"></div>');
				$overlay = $('<div class="overlay"></div>');
				$modal = $('<div class="modal"></div>');
				$content = $('<div id="overlay_'+this.overlayCount+'"  class="content"></div>');
				$close = $('<a class="close" href="#">close</a>');
				
				$modal.hide();
				$overlay.hide();
				$modal.append($title,$content, $close);

				$(document).ready(function(){
					$('body').append($overlay, $modal);						
				});

				$close.click(function(e){
					e.preventDefault();
					method.close();
				});
				
				return method;
			  },
			  
	panel:function(){
				this.overlayCount ++;	
				var 
				method = {},
				$overlay,
				$modal,
				$header,
				$content,
				$close;
				
				// Center the modal in the viewport
				method.center = function () {
					var top, left;
					//top = Math.max($(window).height() - $modal.outerHeight(), 0) / 2;
                    top = 100;
					left = Math.max($(window).width() - $modal.outerWidth(), 0) / 2;

					$modal.css({
						top:top + $(window).scrollTop(), 
						left:left + $(window).scrollLeft()
					});
				};

				// Open the modal
				method.open = function (settings) {
					
					var w_title='',w_w='',w_h='',w_url='',w_data='',w_content='';
				
					if(settings){
						w_title = settings.title;
						w_w = settings.width;
						w_h = settings.height;
						w_url = settings.url;
						w_data = settings.data;
						w_content = settings.content;
					}
					
					if(w_content){ 
						//intant content
						$content.html(w_content);
					}else{
						if(w_url){
							//get content ajax	
							$.ajax({
								   type: "POST",
								   url: w_url,
								   data: 'ajax=1&'+w_data,
								   success: function(data){
									   try{		  
											var data = $.parseJSON(data);
											if(data.html) {
												$content.html(data.html);
											}
									   }catch(e){
											Common.jsonError();   
									   }
								   }
								});	 
							
						}
					}
					
					if(w_title){
						$header.find('H3').html(w_title);	
					}
					
					if(w_w){
						$box.width(w_w);	
					}
					
					if(w_h){
						$box.height(w_h);	
					}
					//$content.empty().append(settings.content);

					$modal.css({
						width: settings.width || 'auto', 
						height: settings.height || 'auto'
					});

					method.center();
					$(window).bind('resize.modal', method.center);
					$modal.show();
					$overlay.show();
				};

				// Close the modal
				method.close = function () {
					$modal.hide();
					$overlay.hide();
					$content.empty();
					$(window).unbind('resize.modal');
				};

				// Generate the HTML and add it to the document
				$overlay = $('<div class="overlay"></div>');
				$modal = $('<div class="modal"></div>');
				$box = $('<div id="overlay_'+this.overlayCount+'" class="box boxOverlay"></div>');
				$header = $('<div class="header"><div class="icon"></div><h3></h3></div>');
				$content = $('<div class="content boxContent"></div>');
				$close = $('<a class="closeWindow" href="#">close</a>');
				
				
				
				
				$box.append($header, $content);
				
				$modal.hide();
				$overlay.hide();
				$modal.append($box, $close);

				$(document).ready(function(){
					$('body').append($overlay, $modal);						
				});
				
				

				$close.click(function(e){
					e.preventDefault();
					method.close();
				});
				
				return method;
			  },
   	panel_ext:function(){
				this.overlayCount ++;	
				var 
				method = {},
				$overlay,
				$modal,
				$header,
				$content,
				$close;
				
				
				
				// Center the modal in the viewport
				method.center = function () {
					var top, left;
					//top = Math.max($(window).height() - $modal.outerHeight(), 0) / 2;
                    top = 100;
					left = Math.max($(window).width() - $modal.outerWidth(), 0) / 2;

					$modal.css({
						top:top + $(window).scrollTop(), 
						left:left + $(window).scrollLeft()
					});
				};

				// Open the modal
				method.open = function (settings) {
					
					var w_title='',w_w='',w_h='',w_url='',w_data='',w_content='';
				
					if(settings){
						w_title = settings.title;
						w_w = settings.width;
						w_h = settings.height;
						w_url = settings.url;
						w_data = settings.data;
						w_content = settings.content;
					}
					
					if(w_content){ 
						//intant content
						$content.html(w_content);
					}else{
						if(w_url){
							//get content ajax	
							$.ajax({
								   type: "POST",
								   url: w_url,
								   data: 'ajax=1&'+w_data,
								   success: function(data){
									   try{		  
											var data = $.parseJSON(data);
											if(data.html) {
												$content.html(data.html);
											}
									   }catch(e){
											Common.jsonError();   
									   }
								   }
								});	 
							
						}
					}
					
					if(w_title){
						$header.find('H3').html(w_title);	
					}
					
					if(w_w){
						$box.width(w_w);	
					}
					
					if(w_h){
						$box.height(w_h);	
					}
					//$content.empty().append(settings.content);

					$modal.css({
						width: settings.width || 'auto', 
						height: settings.height || 'auto'
					});

					method.center();
					$(window).bind('resize.modal', method.center);
					$modal.show();
					$overlay.show();
				};

				// Close the modal
				method.close = function () {
					$modal.hide();
					$overlay.hide();
					$content.empty();
					$(window).unbind('resize.modal');
				};

				// Generate the HTML and add it to the document
				$overlay = $('<div class="overlay"></div>');
				$modal = $('<div class="modal"></div>');
				$box = $('<div id="overlay_'+this.overlayCount+'" class="box boxOverlay"></div>');
				$header = $('');
				$content = $('<div class="content boxContent"></div>');
				$close = $('<a class="closeWindow" href="#">close</a>');
				
				
				
				
				$box.append($header, $content);
				
				$modal.hide();
				$overlay.hide();
				$modal.append($box, $close);

				$(document).ready(function(){
					$('body').append($overlay, $modal);						
				});
				
				

				$close.click(function(e){
					e.preventDefault();
					method.close();
				});
				
				return method;
			  }
              
              
              
			}